<template>
    <div class="menu-list">
        <div v-for="item in list" :key="item.id">
            <div class="time2">
                <span></span>
                <span class="redsapn">已交易</span>
            </div>
            <div @click="todetail(item.id)">
                <!-- num="2"
                desc="03月30日提货" -->
                <van-card
                    :price="item.price"
                    :title="item.shop"
                    :thumb="item.picture"
                >
                    <template #num>
                        <van-button
                            round
                            size="small"
                            type="danger"
                            @click="comment(item.id)"
                            >点击查看</van-button
                        >
                    </template>
                    <template #desc>
                        订单编号：{{ item.number }} <br />
                        <span>订单内容:{{}}</span>
                        交易金额： ￥{{ item.total_price }} <br />
                        交易时间: {{ item.date }}
                    </template>
                </van-card>
            </div>
            <hr />
        </div>
    </div>
</template>

<script setup lang="ts">
import { useCartStore } from '@/stores/cart'
import { type Ref, ref, onMounted } from 'vue'
import { useDetailStore } from '@/stores/detail'
import { useRouter } from 'vue-router'

import axios from 'axios'
import { useAccountStore } from '@/stores/user'
const accountStore = useAccountStore()

const comment = (id) => {
    router.push({ path: '/comment', query: { id } })
}

onMounted(() => {
    getAllOrder()
})
// 获取所有订单列表
const getAllOrder = async () => {
    const data = await axios({
        method: 'get',
        url: 'http://localhost:3000/goods/allorder',
        //post请求参数使用data选项, get参数 params选项
    })
    const { code, info } = data.data
    if (code === 1) {
        // accountStore.account
        list.value = info.list.filter(item => {
            if (item.user == accountStore.account.username && item.order_state == 0) return item
        })
        console.log(list.value)
    } else {
        Toast('erro')
    }
}

const usetDetail = useDetailStore()
const router = useRouter()

const list: Ref<Array<any>> = ref([])
const useCart = useCartStore()
list.value = useCart.list
const tocheckpay = () => {
    router.push({ path: '/checkpay' })
}
// 商品详情
const todetail = (id: number) => {
    router.push({ path: '/detail', query: { id } })
}
</script>

<style scoped lang="scss">
.menu-list {
    margin-top: 10px;
    height: 880px;
    width: 100%;
    display: flex;
    flex-direction: column;

    .time {
        padding: 5px 24px 5px 24px;
        display: flex;
        justify-content: space-between;
        background-color: #ffffff;
    }

    .time2 {
        padding: 5px 24px 5px 24px;
        display: flex;
        justify-content: space-between;
        background-color: #ffffff;

        .redsapn {
            color: red;
        }
    }
    .van-button {
        float: right;
    }
}
</style>
